package com.ruoyi.web.controller.workflow;

import com.baomidou.mybatisplus.annotation.TableField;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.R1;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.workflow.domain.bo.WfModelBo;
import com.ruoyi.workflow.domain.vo.WfModelVo;
import com.ruoyi.workflow.service.IWfCategoryService;
import com.ruoyi.workflow.service.IWfModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import liquibase.pro.packaged.V;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

import static io.lettuce.core.pubsub.PubSubOutput.Type.message;


/**
 * 工作流流程模型管理
 *
 * @author KonBAI
 * @createTime 2022/6/21 9:09
 */
@Api("流程模型")
@RequiredArgsConstructor
@RestController
@RequestMapping("/workflow/model")
public class WfModelController extends BaseController {
    private final IWfModelService modelService;
    private final IWfCategoryService categoryService;

    /**
     * 查询流程模型列表
     *
     * @param modelBo 流程模型对象
     * @param pageQuery 分页参数
     */
    @ApiOperation("流程模型列表")
    @GetMapping("/list")
    public TableDataInfo<WfModelVo> list(WfModelBo modelBo, PageQuery pageQuery){
        return modelService.list(modelBo,pageQuery);
    }

    /**
     * 新增流程模型
     */
    @ApiOperation("新增流程模型")
    @PostMapping
    public R<Void> add(@RequestBody WfModelBo modelBo)
    {
        modelService.insertModel(modelBo);
        return R.ok();
    }

    /**
     *获取流程模型表单详细信息
     */
    @GetMapping("/bpmnXml/{modelId}")
    @ApiOperation("获取流程表单详情信息")
    public R<String> getBpmnXml(@NotNull(message = "不能为空") @PathVariable("modelId") String modelId)
    {
        return R1.ok("操作成功",modelService.queryBpmnXmlById(modelId));
    }

    /**
     * 流程模型部署
     */
    @PostMapping("/deploy")
    public R<Void> deployModel(@RequestParam String modelId){
        return toAjax(modelService.deployModel(modelId));
    }

    /**
     * 保存流程模型图
     */
    @ApiOperation("保存流程模型图")
    @PostMapping("/save")
    public R<String> save(@RequestBody WfModelBo modelBo)
    {
        modelService.saveModel(modelBo);
        return R.ok();
    }

    /**
     * 删除流程模型
     */
    @ApiOperation("删除流程模型")
    @DeleteMapping("/{modelIds}")
    public R<String> remove(@NotEmpty(message = "主键不能删除") @PathVariable String[] modelIds){
        return R.ok();
    }


}
